#!/bin/bash -e

function info() {
    echo Usage: `basename $0` '[-n b] bam interval'
    exit 1
}

while getopts ":p:f:n:r:b:" opt; do
    case  $opt  in
        p) out_prefix=$OPTARG;;
        f) suffix=$OPTARG;;
        n) name=$OPTARG;;
        r) read_th=$OPTARG;;
        b) bed=$OPTARG;;
        *) info;;
    esac
done
shift $(($OPTIND - 1))

if [ $# -lt 2 ]; then info; fi

export var=/mnt/ilustre/app/medical/tools/script/var
. $var
interval=$2

mpp.sh -p$out_prefix -i$interval $1
# varscan.sh -p$out_prefix $out_prefix.mpileup
mutect2.sh -p$out_prefix $1 ~/run/mutect/1.pon.vcf.gz
gunzip -c $out_prefix.mutect2.vcf.gz > $out_prefix.mutect2.vcf

filter_vcf_bed.sh -p$out_prefix.target.snp $out_prefix.varscan.snp.vcf ../target_site_zp.bed
filter_vcf_bed.sh -p$out_prefix.target.indel $out_prefix.varscan.indel.vcf ../target_site_zp.bed

filter_vcf_bed.sh -p$out_prefix.target.mutect2 $out_prefix.mutect2.vcf ../target_site_zp.bed

vcf_extract.sh -p$out_prefix.target.snp $out_prefix.target.snp.filter.vcf CHROM POS GEN[0].FREQ GEN[0].AD GEN[0].DP GEN[0].GQ GEN[0].PVAL GEN[0].RBQ GEN[0].ABQ GEN[0].RDF GEN[0].RDR GEN[0].ADF GEN[0].ADR REF ALT
vcf_extract.sh -p$out_prefix.target.indel $out_prefix.target.indel.filter.vcf CHROM POS GEN[0].FREQ GEN[0].AD GEN[0].DP GEN[0].GQ GEN[0].PVAL GEN[0].RBQ GEN[0].ABQ GEN[0].RDF GEN[0].RDR GEN[0].ADF GEN[0].ADR REF ALT

. $cmd_done
